package manager;

public class ActThread extends Thread
{
    //Reference back to manager
    Manager mgr;
    //Flag to determine if the thread runs
    boolean continueRunning;
    //Length of each “turn”
    long interval;
    
    //Passes reference to manager
    public ActThread(Manager m)
    {
        interval = 1000;
        mgr = m;
    }
    
    /**
     * Sets continueRunning to true and uses that value for a while loop in 
     * which for each iteration calls spawnVeggies, procActions, and 
     * updateBoard. Sleeps between turns for a prescribed duration.
     **/
    public void run()
    {
        continueRunning = true;
        while (continueRunning)
        {
            spawnVeggies();
            procActions();
            updateBoard();
            
            try
            {
                sleep(interval);
            }
            catch(InterruptedException e)
            {
                //What's to do?
            }
        }
    }
    
    /**
     * Sets continueRunning to false
     */
    void haltGame()
    {
        continueRunning = false;
    }
    /**
     * Calls spawnVeggies in Manager
     */
    void spawnVeggies()
    {
        mgr.spawnVeggies();
    }
    
    /**
     * Calls procActions in Manager
     */
    void procActions()
    {
        mgr.procActions();
    }
    
    /**
     * Calls updateBoard in Manager
     */
    void updateBoard()
    {
        mgr.updateBoard();
    }
    /**
     * Sets continueRunning to true and calls start()
     */
    void unHaltGame()
    {
        continueRunning = true;
        start();
    }

}
